package com.borko.healthcare.tapestry.services;

import org.apache.tapestry5.*;
import org.apache.tapestry5.ioc.MappedConfiguration;
import org.apache.tapestry5.ioc.ServiceBinder;
import org.apache.tapestry5.ioc.annotations.InjectService;
import org.apache.tapestry5.services.ValueEncoderFactory;
import org.springframework.context.ApplicationContext;

import com.borko.healthcare.entities.interfaces.Order;
import com.borko.healthcare.persistence.hibernate.services.OrderManager;

public class AppModule {
	public static void bind(ServiceBinder binder) {
	}

	public static void contributeFactoryDefaults(
			MappedConfiguration<String, Object> configuration) {
		configuration.override(SymbolConstants.APPLICATION_VERSION,
				"1.0-SNAPSHOT");
	}

	public static void contributeApplicationDefaults(
			MappedConfiguration<String, Object> configuration) {
		configuration.add(SymbolConstants.SUPPORTED_LOCALES, "en");
	}
	
	@SuppressWarnings("rawtypes")
	public static void contributeValueEncoderSource(
			MappedConfiguration<Class, ValueEncoderFactory> configuration,
			@InjectService("applicationContext") final ApplicationContext applicationContext) {

		ValueEncoderFactory orderFactory = new ValueEncoderFactory() {

			public ValueEncoder create(Class arg0) {
				return new OrderEncoder((OrderManager) applicationContext.getBean("orderManager"));
			}
		};
		configuration.add(Order.class, orderFactory);
	}
}
